package com.yixin.controller;

import com.yixin.anno.Log;
import com.yixin.entity.Emp;
import com.yixin.entity.PageResult;
import com.yixin.entity.Result;
import com.yixin.entity.EmpQueryParam;
import com.yixin.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    @Log
    @PostMapping
    public Result add(@RequestBody Emp emp){
        empService.add(emp);
        return Result.success();
    }

    @Log
    @PutMapping
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();
    }

    @Log
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        empService.deleteByIds(ids);
        return Result.success();
    }


    @Log
    @GetMapping
    public Result findPage(EmpQueryParam  param){
        PageResult<Emp> pageResult = empService.findPage(param);
        return Result.success(pageResult);
    }
}
